package com.ywps.vaas.framework.util

object ConvertUtil {

  /**
   * 定义下滑转驼峰
   * @param str
   * @return
   */
  def underlineToHump(str : String) : String = {
    var spStr : Array[String] = str.split("_")
    //循环这个数组
    var result = ""
    var index = 0
    for(i <- 0 to str.length - 1) {
      if(str.charAt(i) == '_') {
        index = 1 + i
      } else {
        if(i == index && i != 0) {
          result += str.charAt(i).toUpper
        } else {
          result += str.charAt(i)
        }
      }
    }
    result
  }

  /**
   * 驼峰转下滑线
   * @param str
   * @return
   */
  def humpToUnderLine(str : String) : String = {
    var result = ""
    for(char <- str) {
      if(char.isUpper) {
        result += "_" + char
      } else {
        result += char
      }
    }

    result
  }
}
